﻿/**
 * @usage	图片占位符,3D中经常运用。因为在加载显示前需给定一个图片大小的占位Shape.
 * 
 * 
 */
package org.nickro.project.load 
{
	import flash.display.Bitmap;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.display.Stage;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import org.nickro.project.load.SingleLoader;
	import org.nickro.project.events.LoadEvent;
	import org.nickro.project.utils.LibraryManager;
	/**
	 * ...
	 * @author com.nickro
	 */
	public dynamic class ImageBox extends MovieClip
	{
		private var bg:Shape;
		private var _width:Number;
		private var _height:Number;
		private var _url:String;
		private var _content:*;
		private var _loading:MovieClip;
		public function ImageBox(url:String,width:Number,height:Number) 
		{
			_width = width;
			_height = height;
			_url = url;
			this.graphics.beginFill(0xFF0000, 0);
			this.graphics.drawRect(0, 0, _width, _height);
			init();
		}
		
		private function init(e:Event = null):void
		{
			//var ImageLoadbar:Class = LibraryManager.getInstance().libClasses["ImageLoading"] as Class;
			//_loading = new ImageLoadbar;
			_loading = new loading();
			addChild(_loading);
			_loading.x = (_width - _loading.width) * 0.5;
			_loading.y = (_height - _loading.height) * 0.5;
			//if (e) e.target.removeEventListener(Event.ADDED_TO_STAGE, init);
			var loader:SingleLoader = new SingleLoader();
			//loader.addEventListener(LoadEvent.PROGRESS, onLoading);
			loader.addEventListener(LoadEvent.COMPLETE, onLoaded);
			loader.loadSwf(_url);
		}
		
		private function onLoading(e:LoadEvent):void
		{
			//_loading.iLabel_txt.text = String(e.data);
			//dispatchEvent(new LoadEvent(LoadEvent.PROGRESS, e.data));
		}
		
		private function onLoaded(e:LoadEvent):void
		{
			_loading.visible = false;
			removeChild(_loading);
			_content = e.data;
			addChild(_content);
			this.graphics.clear();
			//dispatchEvent(new LoadEvent(LoadEvent.COMPLETE, _content));
		}
		public function get content() { return _content; };
	}

}